/*
 * 文件名               :  SocketHandlerFinder.java
 * 用途                    :  持有特定Id的SocketHandler,全部方法都是线程安全的
 * 最后修改日期:  $LastChangedDate: 2009-10-17 03:54:49 +0000 (Sat, 17 Oct 2009) $
 * 最后修改者     :  $LastChangedBy: wendal1985@gmail.com $
 * 创建者               :  Wendal Chen <wendal1985@gmail.com>
 */
package com.wendal.java.preproxy.server;

import java.util.HashMap;
import java.util.Map;

import com.wendal.java.preproxy.thread.SocketHandler;

public class SocketHandlerFinder {
	private Map<String, SocketHandler> map = new HashMap<String, SocketHandler>();

	public void addObject(SocketHandler socketHandler) {
		if (socketHandler == null || socketHandler.getMyID() == null)
			return;
		
		synchronized (map) {
//			if (map.get(socketHandler.getMyID()) != null) {
//				System.out.println("Key =" + socketHandler.getMyID() + " 已经绑定一个对象");
//			}
			map.put(socketHandler.getMyID(), socketHandler);
		}
	}

	public SocketHandler remove(String key) {
		if(key == null) return null;
		synchronized (map) {
			return map.remove(key);
		}
	}

	public SocketHandler get(String key) {
		if(key == null) return null;
		synchronized (map) {
			return map.get(key);
		}
	}
}
